using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

using Read.Models;
using Read.Services;
using Read.Utility;

namespace Read.Web.Admin
{
    /// <summary>
    /// AjaxController
    /// </summary>
    [Area("Admin")]
    public class AjaxController : Controller
    {
        /// <summary>
        /// 获取后台菜单
        /// </summary>
        /// <returns></returns>
        public IActionResult GetMenu()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return Json(new ResultData<string>() { Result = false, Code = -1, Message = "未登录" });
            }
            else
            {
                var role = User.FindFirst(ClaimTypes.Role).Value;
                var menu = new NodeService();

                ResultMenuModel menulist = menu.getMenu(role.ToInt32());  //JsonConvert.SerializeObject(adminlist);
                return Json(menulist.children);
            }
        }

        /// <summary>
        /// 添加用户时选择角色
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetRoleList()
        {
            var revice = new RoleService();
            var list = revice.getRoleList(new QueryParamsRole());
            var res = new ResultData<List<RoleModel>>()
            {
                Result = true,
                Total = list.Count,
                Data = list
            };
            return Json(res);
        }
    }
}